$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        type:null,
        ids:null,
        init:function () {
            this.form = new xhForm($('#xh_form'));
            this.form.parse();
            this.type = xhTool.getQuery('type');
            this.ids = xhTool.getQuery('ids');
            this.listener();
            this.funObj().loadSuccess();
        },
        listener:function () {
            var $this = this;

            //double处理
            $('.doubleInput').on('change',function () {
                $this.funObj().toFormatDouble($(this).val(), $(this));
            });

            //确认提交
            $('#bt_modal_confirm', parent.document).click(function () {
                $this.funObj().submitAction();
            });


        },
        funObj:function () {
            var $this = this;
            return {
                toFormatDouble:function (number,dom) {
                    var f = parseFloat(number);
                    if (isNaN(f)) {
                        dom.val('0.00');
                    }
                    var f = Math.round(number*100)/100;
                    var s = f.toString();
                    var rs = s.indexOf('.');
                    if (rs < 0) {
                        rs = s.length;
                        s += '.';
                    }
                    while (s.length <= rs + 2) {
                        s += '0';
                    }
                    dom.val(s);
                },
                submitAction:function () {
                    $this.ids = $this.ids.split(',');
                    $this.form.submit('ims/detail/modifyInfo', {ids:$this.ids, type:$this.type},function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        window.top.xhTop.closeModal();
                    })
                },
                loadSuccess:function () {
                    if (info) {
                        var str = '<tr>\n' +
                            '                <td><label style="width: 75px;">商品类型</label></td>\n' +
                            '                <td>\n' +
                            '                    <select name="prodId" class="form-control" style="width: 200px;" >\n' +
                            '                        <option value="">请选择</option>\n' ;
                        $.each(prods, function (id,text) {
                            str +='<option value="'+id+'">'+text+'</option>\n';
                        });
                        str +='                    </select>\n' +
                            '                </td>\n' +
                            '                <td><label style="width: 75px;">数目</label></td>\n' +
                            '                <td>\n' +
                            '                    <input class="form-control" name="num" style="width: 200px;" type="number" step="0.01">\n' +
                            '                </td>\n' +
                            '            </tr>';
                        $('[name=schoolId]').parent().parent().before(str);
                        $this.form.fill(info);
                    }
                    $('[name=devType],[name=schoolId]').select2();
                }
            }
        }
    }
};